﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style type="text/css">
    .form .formValue input.form-control {
        line-height: 32px;
        padding: 0px;
        resize: none;
        border-radius: 0px;
        box-shadow: none;
        text-indent: 5px
    }

    .textValue {
        width: 100%;
    }

    .selectbox {
        color: #444;
        line-height: 34px;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        height: 34px;
        width: 100%;
    }

    .search {
        margin-left: 10px;
        padding: 0px;
    }

    table td {
        height: 40px;
        line-height: 40px;
    }

    .zdyPanel {
        background-color: #fff;
        border-top: 1px solid #ddd;
        border-left: 1px solid #ddd;
        border-right: 1px solid #ddd;
        margin: 0px;
        float: left;
        width: 100%;
    }

    .zdyTool {
        float: left;
        padding-left: 10px;
        width: 100%;
    }

    .zdyBar {
        padding: 0px;
        margin: 0px;
        margin-top: 3px;
    }

    .zdyUL {
        list-style-type: none;
        margin: 5px 0px 0px -3px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 24px;
            line-height: 22px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .autocomplete-suggestions {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        border: 1px solid #999;
        background: #FFF;
        cursor: default;
        overflow: auto;
        -webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        -moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-no-suggestion {
        padding: 2px 5px;
    }

    .zdyGirdPanel {
        width: 100%;
        margin: 0px;
        padding: 0px;
        float: left;
    }

    .zdyContentPanel {
        width: 100%;
        margin: 5px 0px 0px 0px;
        padding: 0px;
        float: left;
    }

    .zdyFont {
        padding-left: 5px;
        color: #ff6a00;
    }

    .zdyUL {
        list-style-type: none;
        margin: 5px 0px 0px -3px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 24px;
            line-height: 22px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
                color: #337ab7;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .zdyGirdPanel {
        padding-top: 3px;
    }

    .form .formValue {
        padding: 1px 3px;
    }
</style>
<script>
    var resultData = {};
    $(function () {
        GetItems();
        gridList();
        $("#state_horizon a.btn-default").click(function () {
            $("#state_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            $('#btn_search').trigger("click");
        });
        $("#F_ApplyType").select2();
    });

    function btn_onSearch() {
        ReloadGridList();
    }

    function GetItems() {     
        resultData=getCache("CHECK_INDEX");
        if (resultData.length <= 0) {
            $.ajax({
                url: "/CheckManager/CheckInfos/GetItemListJson",
                dataType: "json",
                async: false,
                success: function (data) { 
                    resultData = data;
                    InitControl();
                    setCache("CHECK_INDEX", resultData);
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        }
        else {            
            InitControl();
        }
    }

    function InitControl() {
        var F_ApplyType = resultData.F_ApplyType;
        for (var i = 0; i < F_ApplyType.length; i++) {
            $("#F_ApplyType").append("<option value='" + F_ApplyType[i].F_ItemCode + "'>" + F_ApplyType[i].F_ItemName + "</option>");
        }

        var Users = [];
        var SiteUsers = resultData.Users;
        for (var i = 0; i < SiteUsers.length; i++) {
            Users.push({ value: SiteUsers[i].F_RealName, data: SiteUsers[i].F_Id });
        }

        $("#F_UserName").autocomplete({
            lookup: Users,
            onSelect: function (suggestion) {
                $("#hd_F_UserName").val(suggestion.data);
            }
        });
    }

    function gridList() {
        var $gridList = $("#gridList");
        var queryJson = {
        };
        $gridList.dataGrid({
            url: "/CheckManager/CheckInfos/GetGridData",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: 670,
            colModel: [
                { label: '单号', name: 'F_OrderId', width: 50 },
                { label: '批次号', name: 'F_No', width: 120 },
                {
                    label: '申请类型', name: 'F_ApplyType', width: 120, align: 'left', formatter: function (cellvalue) {
                        return GetDictionaries(cellvalue, 'F_ApplyType');
                    }
                },
                {
                    label: '审核部门', name: 'CheckDepartment', align: 'left', formatter: function (cellvalue) {
                        return GetDictionaries(cellvalue, 'CheckDepartment');
                    }
                },
                { label: '审核人', name: 'CheckUserName', width: 120, align: 'left' },
                { label: '审核内容', name: 'F_CheckContent', width: 150, align: 'left' },
                {
                    label: '申请部门', name: 'ApplyDepartment', width: 120, align: 'left', formatter: function (cellvalue) {
                        return GetDictionaries(cellvalue, 'ApplyDepartment');
                    }
                },
                { label: '申请人', name: 'ApplyUserName', align: 'left' },
                { label: '申请时间', name: 'F_CreatorTime', align: 'left' },
                {
                    label: '审核状态', name: '', align: 'left', width: 140, formatter: function (cellvalue, options, rowObject) {
                        if (rowObject["F_State"] == null) {
                            return "<span style=\"color:#337ab7;padding: 5px 10px;\">待审核</span>";
                        } else if (rowObject["F_State"] == "1") {
                            return "<span style=\"color:#1ABC9C;padding: 5px 10px;\">审核通过</span>";
                        } else if (rowObject["F_State"] == "0") {
                            return "<span style=\"color:red;padding: 5px 10px;\">审核驳回</span>";
                        } else {
                            return "<span style=\"color:red;padding: 5px 10px;\">审核驳回</span>";
                        }
                    }
                },                
                { label: '', name: 'F_FlowId', hidden: true },
                { label: '', name: 'ApplyTypeNo', hidden: true },
                { label: '', name: 'F_CheckUserId', hidden: true },
                { label: '', name: 'F_Id', hidden: true },
                { label: '', name: 'F_No', hidden: true },
                { label: '', name: 'orderF_State', hidden: true },
            ],
            pager: "#gridPager",
            viewrecords: true,
            multiselect: false,
            sortname: 'F_Id',
            rowNum: 20,
            rowList: [20, 40, 60],
            ondblClickRow: function (rowid, iRow, iCol, e) {
                CheckView();
            },
            loadComplete: function (data) {
            }
        });
    }

    function ReloadGridList() {
        var $gridList = $("#gridList");
        var queryJson = {
            F_ApplyUserId: $("#hd_F_UserName").val(),
            F_ApplyType: $("#F_ApplyType").val(),
            F_CreatorTime: $("#F_CheckDate").val(),
            F_State: $("#state_horizon a.active").attr('data-value')
        };
        $gridList.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }

    function btn_CheckOk(obj) {
        var opts = { btn: ['是', '否'] };
        $.modalConfirm('您确定审核通过吗？', function (flag, index) {
            if (flag) {
                $.ajax({
                    url: "/CheckManager/CheckInfos/CheckOrder?F_Id=" + obj.id + "&State=1",
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        ReloadGridList();
                    }, error: function (XMLHttpRequest, textStatus, errorThrown) {

                    }, complete(XMLHttpRequest, textStatus) {

                    }
                });
                $.modalConfirmClose(index);
            }
        });
    }

    function btn_CheckNo(obj) {
        var opts = { btn: ['是', '否'] };
        $.modalConfirm('您确定审核通过吗？', function (flag, index) {
            if (flag) {
                $.ajax({
                    url: "/CheckManager/CheckInfos/CheckOrder?F_Id=" + obj.id + "&State=0",
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        ReloadGridList();
                    }, error: function (XMLHttpRequest, textStatus, errorThrown) {

                    }
                });
                $.modalConfirmClose(index);
            }
        });
    }

    function CheckView() {
        var rowObj = $("#gridList").jqGridRowValue();
        if (rowObj["ApplyTypeNo"] == "1") {
            $.modalOpen({
                id: "checkDetail",
                title: "场地档期审核详情",
                url: "/CheckManager/CheckInfos/Details?F_OrderId=" + rowObj["F_OrderId"] + "&F_Id=" + rowObj["F_Id"] + "&F_FlowId=" + rowObj["F_FlowId"] + "&ApplyType=" + rowObj["ApplyTypeNo"] + "&F_CheckUserId=" + rowObj["F_CheckUserId"] + "&orderF_State=" + rowObj["orderF_State"] + "&F_No=" + rowObj["F_No"],
                width: "1200px",
                height: "650px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                },
                btn: null
            });
        } else if (rowObj["ApplyTypeNo"] == "2") {
            $.modalOpen({
                id: "checkLook",
                title: "场地带看审核详情",
                url: "/CheckManager/CheckInfos/OrderTakelookDetail?F_OrderId=" + rowObj["F_OrderId"] + "&F_Id=" + rowObj["F_Id"] + "&F_FlowId=" + rowObj["F_FlowId"] + "&ApplyType=" + rowObj["ApplyTypeNo"] + "&F_CheckUserId=" + rowObj["F_CheckUserId"] + "&orderF_State=" + rowObj["orderF_State"] + "&F_No=" + rowObj["F_No"],
                width: "1200px",
                height: "650px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                },
                btn: null
            });
        }        
        else if (rowObj["ApplyTypeNo"] == "3") {
            $.modalOpen({
                id: "checkPrice",
                title: "意向场地报价申请",
                url: "/CheckManager/CheckInfos/OrderPriceCheck?F_OrderId=" + rowObj["F_OrderId"] + "&F_Id=" + rowObj["F_Id"] + "&F_FlowId=" + rowObj["F_FlowId"] + "&ApplyType=" + rowObj["ApplyTypeNo"] + "&F_CheckUserId=" + rowObj["F_CheckUserId"] + "&orderF_State=" + rowObj["orderF_State"] + "&F_No=" + rowObj["F_No"],
                width: "1200px",
                height: "650px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                },
                btn: null
            });
        } else if (rowObj["ApplyTypeNo"] == "4") {
            $.modalOpen({
                id: "checkOrderPrice",
                title: "报价单审核详情",
                url: "/CheckManager/CheckInfos/OrderPriceDbCheck?F_OrderId=" + rowObj["F_OrderId"] + "&F_CheckId=" + rowObj["F_Id"] + "&F_FlowId=" + rowObj["F_FlowId"] + "&ApplyType=" + rowObj["ApplyTypeNo"] + "&F_CheckUserId=" + rowObj["F_CheckUserId"] + "&orderF_State=" + rowObj["orderF_State"] + "&F_No=" + rowObj["F_No"],
                width: "1200px",
                height: "650px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                },
                btn: null
            });

        } else if (rowObj["ApplyTypeNo"] == "5") {
            $.modalOpen({
                id: "checkReserve",
                title: "场地预定审核详情",
                url: "/CheckManager/CheckInfos/OrderReserveDetail?F_OrderId=" + rowObj["F_OrderId"] + "&F_Id=" + rowObj["F_Id"] + "&F_FlowId=" + rowObj["F_FlowId"] + "&ApplyType=" + rowObj["ApplyTypeNo"] + "&F_CheckUserId=" + rowObj["F_CheckUserId"] + "&orderF_State=" + rowObj["orderF_State"] + "&F_No=" + rowObj["F_No"],
                width: "1200px",
                height: "650px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                },
                btn: null
            });
        } else if (rowObj["ApplyTypeNo"] == "6") {
            $.modalOpen({
                id: "checkUsing",
                title: "用印申请审核详情",
                url: "/CheckManager/CheckInfos/UsingCheck?F_OrderId=" + rowObj["F_OrderId"] + "&F_Id=" + rowObj["F_Id"] + "&F_FlowId=" + rowObj["F_FlowId"] + "&ApplyType=" + rowObj["ApplyTypeNo"] + "&F_CheckUserId=" + rowObj["F_CheckUserId"] + "&orderF_State=" + rowObj["orderF_State"] + "&F_No=" + rowObj["F_No"],
                width: "1200px",
                height: "650px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                },
                btn: null
            });
        } else if (rowObj["ApplyTypeNo"] == "7") {
            $.modalOpen({
                id: "checkSignContract",
                title: "合同审核详情",
                url: "/CheckManager/CheckInfos/OrderSignContractDetail?F_OrderId=" + rowObj["F_OrderId"] + "&F_Id=" + rowObj["F_Id"] + "&F_FlowId=" + rowObj["F_FlowId"] + "&ApplyType=" + rowObj["ApplyTypeNo"] + "&F_CheckUserId=" + rowObj["F_CheckUserId"] + "&orderF_State=" + rowObj["orderF_State"] + "&F_No=" + rowObj["F_No"],
                width: "1200px",
                height: "650px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                },
                btn: null
            });
        }
    }

    function GetDictionaries(value, type) {
        if (type == "F_ApplyType") {
            for (var i = 0; i < resultData.F_ApplyType.length; i++) {
                if (value == resultData.F_ApplyType[i].F_ItemCode) {
                    return resultData.F_ApplyType[i].F_ItemName;
                }
            }
            return '';
        } else if (type == "CheckDepartment") {
            for (var i = 0; i < resultData.Organize.length; i++) {
                if (value == resultData.Organize[i].F_Id) {
                    return resultData.Organize[i].F_FullName;
                }
            }
            return '';
        } else if (type == "ApplyDepartment") {
            for (var i = 0; i < resultData.Organize.length; i++) {
                if (value == resultData.Organize[i].F_Id) {
                    return resultData.Organize[i].F_FullName;
                }
            }
            return '';
        }
    }

</script>
<div class="zdyPanel">
    <div class="zdyBar" style="float:left;white-space:nowrap;width:50%;">
        <div class="search">
            <table class="form" style="width:100%;">
                <tr>
                    <td class="formValue">
                        <div class="input-group" style="width:100%;">
                            <input type="text" id="F_UserName" class="form-control textValue" placeholder="请输申请姓名" />
                            <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                            <input type="hidden" name="hd_F_UserName" id="hd_F_UserName" value="" />
                        </div>
                    </td>
                    <td class="formValue">
                        <select id="F_ApplyType" name="F_ApplyType" class="form-control selectbox">
                            <option value="">==请选择审核类型==</option>
                        </select>
                    </td>
                    <td class="formValue">
                        <input type="text" id="F_CheckDate" name="F_CheckDate" class="form-control input-wdatepicker required" onfocus="WdatePicker()" placeholder="请输入申请时间" />
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <div id="state_horizon" class="btn-group">
                            <a class="btn btn-default active" data-value="">全部</a>
                            <a class="btn btn-default" data-value="1">审核通过</a>
                            <a class="btn btn-default" data-value="0">驳回</a>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="zdyBar" style="float:right;white-space:nowrap;width:50%;padding-top:5px;">
        <div style="float:right;padding-right:5px;">
            <div class="btn-group">
                <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            </div>
            <div class="btn-group">
                <a class="btn btn-primary" id="btn_search" onclick="btn_onSearch()">按条件搜索</a>
            </div>
        </div>
    </div>
</div>
<div class="zdyGirdPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>